<?php
 $q=$_GET["q"];
$hint="";
if(strlen($q)>0&&$q!="0")
{
include_once ("Login/databaseconnection.php");
require_once ("Login/config.php");
$dbname = $db;
$arr="";
$sql ="SHOW TABLES FROM $dbname";
$resulttable = mysql_query($sql);
while ($rowtable = mysql_fetch_row($resulttable))
{
if($rowtable[0]!="user"&&substr($rowtable[0],0,4)!="dele")
{
$que="SHOW COLUMNS FROM $rowtable[0]";
$resultcol=mysql_query($que);
while ($rowcol= mysql_fetch_row($resultcol))
{
$getque="SELECT * FROM $rowtable[0]";
$result=mysql_query($getque);
if(mysql_num_rows($result)!=0)
{
while($row=mysql_fetch_array($result))
{
$value=substr($row[$rowcol[0]],0,strlen($q));
if(strcasecmp($value,$q)==0){
if($arr=="")
{
$arr=$row[$rowcol[0]];
}
else
{
$arr=$arr.",".$row[$rowcol[0]];
}
}
}
}
}
}
}
 $array= explode(",",$arr);
if(count($array)>5)
{
   $hint=$hint.'<div style="height:200px; overflow-Y:scroll; ">';
}
for ($i = 0; $i <count($array); $i++) 
{
 $temp =$array[$i];
  if($temp!="")
  {
  $hint=$hint.'<li onClick="fill(\''.$temp.'\');">'.$temp.'</li>';
  }
  $j = $i;
  for ($k = 0; $k <count($array); $k++) 
  {
    if ($k != $j) {
      if ($temp == $array[$k]) 
	  {
        $array[$k]="";
      }
    }
  }
}
if(count($array)>5)
{
$hint=$hint.'</div>';
}
}
if($hint=="")
{
$response="No suggestions";
}
else
{
$response=$hint;
}
echo $response;
?>